package com.audaque.springboot.foshanupload.web.reactivedemo.handler;

import com.audaque.springboot.foshanupload.web.reactivedemo.reactor.MultiThreadEchoServerReactor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;


/**
 * 新连接事件处理器
 */
@Component
@Slf4j
public class MyAcceptorHandler implements Runnable {

    @Autowired
    private MultiThreadEchoServerReactor multiThreadEchoServerReactor;

    @Autowired
    private MultiThreadEchoHandler multiThreadEchoHandler;


    public void run() {
        try {
            multiThreadEchoHandler.init();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        if (multiThreadEchoServerReactor.getNext().incrementAndGet() == multiThreadEchoServerReactor.getWorkSelectors().length) {
            multiThreadEchoServerReactor.getNext().set(0);
        }
    }
}

